package com.best.oasis.settlement.biz.facade.employee
{
	import com.best.oasis.flexbase.util.BeanUtils;
	import com.best.oasis.settlement.biz.facade.base.BaseFacade;
	import com.best.oasis.settlement.biz.facade.base.SuperResponder;
	import com.best.oasis.settlement.common.vo.base.BaseBizVO;
	import com.best.oasis.settlement.common.vo.employee.EmployeeVO;
	import com.best.oasis.settlement.util.page.BasePageSO;
	import com.best.oasis.settlement.util.page.PageList;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class EmployeeFacade extends BaseFacade
	{
		
		
		/**
		 * get an object
		 * @param id
		 * @param result
		 * @param callback
		 * 
		 */
		override public function get(id:Number, result:BaseBizVO, callback:Function = null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					if(event.result != null){
						BeanUtils.copyProperties(result, EmployeeVO(event.result));
						if(callback != null){
							callback();
						}
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("获取数据失败！" + event.fault.faultString);
				});
			delegate.get(id).addResponder(responder);
		}
		/**
		 * create an object
		 * @param vo
		 * @param callback
		 * 
		 */
		override public function create(vo:BaseBizVO, callback:Function = null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					if(event.result != null){
						Alert.show("保存成功！");
						if(callback != null){
							callback();
						}
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("保存失败！" + event.fault.faultString);
				});
			delegate.create(vo).addResponder(responder);
		}
		/**
		 * get object paged list 
		 * @param so
		 * @param result
		 * @param callback
		 * 
		 */
		override public function getPageList(so:BasePageSO, result:PageList, callback:Function = null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					var tResult:PageList = PageList(event.result);
					BeanUtils.copyProperties(result, tResult);
					if(callback != null){
						callback();
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("获取列表失败！" + event.fault.faultString);
				});
			delegate.getPageList(so).addResponder(responder);
		}
		/**
		 * remove objects 
		 * @param ids
		 * @param pageList
		 * @param callback
		 * 
		 */
		override public function remove(ids:ArrayCollection, pageList:PageList, callback:Function = null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					Alert.show("删除成功！");
					if(pageList != null){
						BeanUtils.removeByIds(pageList.list, ids);
						pageList.fullListSize -= ids.length;
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("删除失败！");
				});
			delegate.remove(ids).addResponder(responder);
		}
		/**
		 * update an object 
		 * @param vo
		 * @param pageList
		 * @param callback
		 * 
		 */
		override public function update(vo:BaseBizVO, pageList:PageList, callback:Function = null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					var vo:EmployeeVO = EmployeeVO(event.result);
					if(event.result != null){
						Alert.show("保存成功！");
					}
					if(pageList != null){
						BeanUtils.updateItem(pageList.list, vo);
					}
					if(callback != null){
						callback();
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("保存失败！" + event.fault.faultString);
				});
			delegate.update(vo).addResponder(responder);
		}
		
	}
}
